

#include <material_editor/materialview.h>
#include <material_editor/effecteditor.h>
#include <genericdeletedialog.h>
#include <genericrenamedialog.h>
#include <genericsavedialog.h>
#include <session.h>



void MaterialView::EffectEdit (Effect *effect)
{
  if (!OpenEditor(effect))
    {
      InsertEditor(new EffectEditor (effect, this));
    }
}



void MaterialView::EffectEditCurrent ()
{
  EffectItem* item = get_current_item<EffectItem>(_overview);
  if (!item)
    {
      return;
    }
  EffectEdit (item->GetEffect());
}



void MaterialView::EffectAdd()
{
  CategoryItem* item = get_current_item<CategoryItem>(_overview);
  if (!item)
    {
      return;
    }

  GenericRenameDialog dlg (Session::Get()->GetMainWindow());
  dlg.SetType("Create new effect", "");
  dlg.SetName("New Effect");
  dlg.SetCategory(item->GetCategory());
  if (dlg.exec() == QDialog::Rejected)
    {
      return;
    }


  _selectNewItems = true;
  Effect* effect = _manager->CreateEffect();
  effect->SetName(dlg.GetName());
  effect->SetCategory(dlg.GetCategory());

  if (_manager->AddEffect(effect))
    {
      EffectEdit(effect);
    }
  _selectNewItems = false;
}

void MaterialView::EffectAdded(Effect *effect)
{
  AddItem (new EffectItem(this, effect), effect);
}

void MaterialView::EditEffect(Effect *effect)
{
  EffectEdit(effect);
}
